--- description: Getting Started with Plotly for Python. has_thumbnail: False language: python layout: base name: Getting Started with Plotly page_type: u-guide permalink: python/getting-started/ redirect_from: ['python/getting_started/', '/python/pytables/'] --- {% raw %}
The plotly Python library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases.
Built on top of the Plotly JavaScript library (plotly.js), plotly enables Python users to create beautiful interactive web-based visualizations that can be displayed in Jupyter notebooks, saved to standalone HTML files, or served as part of pure Python-built web applications using Dash. The plotly Python library is sometimes referred to as "plotly.py" to differentiate it from the JavaScript library.
Thanks to deep integration with our Kaleido image export utility, plotly also provides great support for non-web contexts including desktop editors (e.g. QtConsole, Spyder, PyCharm) and static document publishing (e.g. exporting notebooks to PDF with high-quality vector images).
This Getting Started guide explains how to install plotly and related optional pages. Once you've installed, you can use our documentation in three main ways:
For information on using Python to build web applications containing plotly figures, see the Dash User Guide.
We also encourage you to join the Plotly Community Forum if you want help with anything related to plotly.
plotly may be installed using pip:
$ pip install plotly
or conda:
$ conda install -c plotly plotly
If you want to use Plotly Express, install its required dependencies with:
pip install plotly[express]
You'll also need to install a supported dataframe library.
Dash is the best way to build analytical apps in Python using Plotly figures. To run the app below, run pip install dash, click "Download" to get the code and run python app.py.
Get started with the official Dash docs and learn how to effortlessly style & deploy apps like this with Dash Enterprise.
Sign up for Dash Club → Free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.
To use plotly in JupyterLab, install the jupyterlab and anywidget packages in the same environment as you installed plotly, using pip:
$ pip install jupyterlab anywidget
or conda:
$ conda install jupyterlab anywidget
Launch JupyterLab with:
$ jupyter lab
and display plotly figures inline:
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()
or using FigureWidget objects.
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
import plotly.graph_objects as go
fig_widget = go.FigureWidget(fig)
fig_widget
See Displaying Figures in Python for more information on the renderers framework, and see Plotly FigureWidget Overview for more information on using FigureWidget.
See the Troubleshooting guide if you run into any problems with JupyterLab, particularly if you are using multiple Python environments inside Jupyter.
For use in the classic Jupyter Notebook, install the notebook and ipywidgets
packages using pip:
pip install "notebook>=7.0" "anywidget>=0.9.13"
or conda:
conda install "notebook>=7.0" "anywidget>=0.9.13"
These packages contain everything you need to run a Jupyter notebook...
$ jupyter notebook
and display plotly figures inline using the notebook renderer...
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()
or using FigureWidget objects.
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
import plotly.graph_objects as go
fig_widget = go.FigureWidget(fig)
fig_widget
See Displaying Figures in Python for more information on the renderers framework, and see Plotly FigureWidget Overview for more information on using FigureWidget.
plotly.py supports static image export,
using the either the kaleido
package (recommended, supported as of plotly version 4.9) or the orca
command line utility (legacy as of plotly version 4.9).
The kaleido package has no dependencies and can be installed
using pip...
$ pip install -U kaleido
or conda.
$ conda install -c plotly python-kaleido
While Kaleido is now the recommended image export approach because it is easier to install
and more widely compatible, static image export
can also be supported
by the legacy orca command line utility and the
psutil Python package.
These dependencies can both be installed using conda:
conda install -c plotly plotly-orca==1.3.1 psutil
Or, psutil can be installed using pip...
pip install psutil
and orca can be installed according to the instructions in the orca README.
Some plotly.py features rely on fairly large geographic shape files. The county
choropleth figure factory is one such example. These shape files are distributed as a
separate plotly-geo package. This package can be installed using pip...
$ pip install plotly-geo==1.0.0
or conda.
$ conda install -c plotly plotly-geo=1.0.0
See USA County Choropleth Maps in Python for more information on the county choropleth figure factory.
Once you've installed, you can use our documentation in three main ways:
For information on using Python to build web applications containing plotly figures, see the Dash User Guide.
We also encourage you to join the Plotly Community Forum if you want help with anything related to plotly.
Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash at https://dash.plot.ly/installation.
Everywhere in this page that you see fig.show(), you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:
import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.add_trace( ... )
# fig.update_layout( ... )
from dash import Dash, dcc, html
app = Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter